<?php

function CreateDBConnection() {

	$handle = mysql_pconnect($GLOBALS["db_host"], $GLOBALS["db_username"], $GLOBALS["db_password"])
			or die("Unable to connect to database");
	mysql_select_db($GLOBALS["db_name"], $handle)
			or die ("Database not found");
}


function getEmailAddress($emailFieldName, $id, $moduleName) {

	$db_name = $GLOBALS["db_name"];

	$query = "SELECT email_address FROM ".$db_name.".email_addresses ea";
	$query = $query." JOIN ".$db_name.".email_addr_bean_rel eabr";
  	$query = $query." ON eabr.email_address_id = ea.id";
	$query = $query." WHERE eabr.bean_module = '".$moduleName."'";
	$query = $query." AND eabr.bean_id = '".$id."'";

	$index = $emailFieldName[strlen($emailFieldName)-1];
	if ($index == "")
		$index = "0";

	$query = $query." LIMIT ".$index.",1";

	return $query;


}


?>
